<?php
namespace App\Http\Controllers;

use App\Models\Address;
use App\Services\LogisticsService;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Input;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Validator;

/**
 *
 * 物流查询控制器
 *
 * @author maqu
 *
 */
class LogisticsController extends BaseController {

    /**
     * @apiDefine DefineCommonParamters
     *
     * @apiParam {String} version [O] 接口版本号，不传默认为1.0.0。
     * @apiParam {String} timestamp [M] 访问接口的事件戳
     * @apiParam {String} token [M] 防篡改验证字段
     * @apiParam {String} device_sn [O]设备唯一码
     *
     */

    /**
     *
     * 查询地址
     * @return mixed
     */
    public function query(){

        //参数获取
        $express_com= Input::get('express_com');
        $express_no= Input::get('express_no');

        //参数验证
        if(!$express_com || !$express_no){
            return $this->args_invalid();
        }

        //调用快递100

        //初始化
        $ch = curl_init();

        //设置选项，包括URL
        curl_setopt($ch, CURLOPT_URL, "http://www.kuaidi100.com/query?type=$express_com&postid=$express_no&id=1&temp=0.7060015059606141");
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_HEADER, 0);

        //执行并获取HTML文档内容
        $output = curl_exec($ch);

        //释放curl句柄
        curl_close($ch);
        
        return $output;
	}
    /**
     *
     * 运费查询控制器
     *
     * @author maqu
     *
     */
    public function getLogistics(LogisticsService $logisticsService){
        //获取参数
        $region_id = Input::get('region_id');
        $goods_id = Input::get('goods_id');
        //参数验证
        if(!$region_id || !$goods_id){
            return $this->args_invalid();
        }
        $data = $logisticsService->getPostage($goods_id,$region_id);
        return $this->success($data);
    }

}
